<template>
  <ele-page>
    <ele-card>
      <div style="padding: 24px 40px">
        <p
          ><el-tag
            >操作说明：在会员列表里面找到要合并的账号的ID在此输入提交确认即可</el-tag
          ></p
        >
        <p
          ><el-tag type="danger"
            >合并后，不要的账号除个人信息（姓名、手机、学校、身份证号、身高、提现信息）之外的信息：</el-tag
          ></p
        >
        <p
          ><el-tag type="warning"
            >报名记录、排队记录、钱包明细记录、钱包余额、提现记录、积分记录、积分余额、积分兑换记录</el-tag
          ></p
        >
        <p
          ><el-tag type="warning"
            >预支工资记录、账单、还款记录、充值记录、推荐工作记录、下线、工资记录、备注信息、黑名单记录</el-tag
          ></p
        >
        <p><el-tag type="danger">将全部归属到新账号</el-tag></p>
      </div>
      <el-form label-width="120px">
        <el-form-item label="不要的账号">
          <el-input
            v-model="oldId"
            style="width: 200px"
            placeholder="账号的id"
          />
        </el-form-item>
        <el-form-item label="保留的账号">
          <el-input
            v-model="newId"
            style="width: 200px"
            placeholder="账号的id"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="success" :loading="loading" @click="showConfirm"
            >提交</el-button
          >
          <!-- <el-button @click="onCancel">Cancel</el-button> -->
        </el-form-item>
      </el-form>
    </ele-card>
  </ele-page>
</template>

<script setup>
  import { ref } from 'vue';
  import { mergeMember } from '@/api/student';
  import { EleMessage } from 'ele-admin-plus/es';
  import { ElMessageBox } from 'element-plus/es';

  const newId = ref('');
  const oldId = ref('');
  const merge = ref('确认');
  /** 提交状态 */
  const loading = ref(false);
  const submitForm = () => {
    mergeMember({ oldId: oldId.value, newId: newId.value, merge: merge.value })
      .then(() => {
        EleMessage.success('操作成功!');
        newId.value = '';
        oldId.value = '';
        merge.value = '确认';
        loading.value = false;
      })
      .catch(() => {
        loading.value = false;
      });
  };
  const showConfirm = () => {
    loading.value = true;
    mergeMember({ oldId: oldId.value, newId: newId.value, merge: merge.value })
      .then((response) => {
        ElMessageBox.confirm(response, '系统提示', {
          type: 'warning',
          draggable: true
        })
          .then(() => {
            merge.value = '合并';
            submitForm();
          })
          .catch(() => {
            loading.value = false;
          });
      })
      .catch(() => {});
  };
</script>
